#include "bencode.h"

bList::bList(const char *bList) : bItem(B_LIST)
{
	const char *ptr = &(bList[1]);
	while (ptr[0] != 'e')
	{
		bItem *item = bDecode(ptr);
		ptr += item->GetCharOffset();
		m_list.push_back(item);
	}
	m_charoffset = ptr+1 - bList;
}

bList::~bList()
{
	vector<bItem*>::iterator i;
	for (i = m_list.begin(); i != m_list.end(); i++)
	{
	    delete (*i);
	}
	m_list.clear();
}

bItem* bList::GetItemFromIndex(int index)
{
	return m_list[index];
}

unsigned bList::GetNumItems()
{
	return m_list.size();
}
